package com.xpu.stock.config;

import com.xpu.stock.utils.IdWorker;
import com.xpu.stock.utils.ParserStockInfoUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 定义公共配置类
 */
@Configuration
public class CommonConfig {
    /**
     * 定义密码加密和解密器bean
     * @return
     */
    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }

    /**
     * 配置基于雪花算法参与运算生成全局唯一ID
     * 参与运算的参数
     * 时间戳+机房ID+机器ID+序列号
     * @return
     */
    @Bean
    public IdWorker idWorker(){
        return new IdWorker(2L,1L);
    }
    @Bean
    public ParserStockInfoUtil parserStockInfoUtil(IdWorker idWorker){
        return new ParserStockInfoUtil(idWorker);
    }
}
